# 导入pymysql模块
import pymysql

# 获取数据库连接
db = pymysql.connect(host="localhost", user="root",
                     password="1223@141x", db="mydb", charset="utf8")

# 创建游标对象
cursor = db.cursor()

# 定义SQL操作
sql = "select * from test"

try:
    cursor.execute(sql)
    while True:
        data = cursor.fetchone()
        if data == None:
            break
        print(data)
except:
    print("SQL执行错误！")

# 执行SQL操作
# cursor.execute("select version()")

# 解析结果
# data = cursor.fetchone()
# print(data)

# 关闭数据库连接
db.close()
